package com.yulebaby.callsenter.utils;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Author: Zhangbo
 * Time: 2016年11月28日
 */
public class ThreadUtils {
    public static final String TAG = "ThreadUtils";

    private static Executor sExecutor = Executors.newSingleThreadExecutor();

    private static Handler sHandler = new Handler(Looper.getMainLooper());

    public static void runOnUiThread(Runnable runnable) {
        sHandler.post(runnable);
    }

    public static void runOnUiThreadDelay(Runnable runnable, long delayMillis) {
        sHandler.postDelayed(runnable, delayMillis);
    }

    public static void runOnBackgroundThread(Runnable runnable) {
        sExecutor.execute(runnable);
    }

    private static ExecutorService taskExecutorService = Executors.newCachedThreadPool();

    public static ExecutorService getExecutor() {
        return taskExecutorService;
    }

    public static Executor getSingleExecutor() {
        return sExecutor;
    }

}
